
window.addEvent("domready", function () {
	$$(".GoodsSearchWrap .buy-select").each(function (a) {
		new QMenu(a, $E(".buy-select-list", a));
	});
});
window.addEvent("domready", function () {
	var d = new Cookie("S[GFAV]", {duration:365});
	var b = {"star-on":"off", "star-off":"on", off:"Del", on:"Add", off_:"erase", on_:"include"};
	var a = function (g, h, f) {
		if (h == "on") {
			g.className = "star-on";
			var e = g.children[0];
			while (e.nodeType != 3) {
				e = e.firstChild;
			}
			e.nodeValue = "\u5df2\u52a0\u5165\u6536\u85cf";
		} else {
			g.className = "star-off";
			var e = g.children[0];
			while (e.nodeType != 3) {
				e = e.firstChild;
			}
			e.nodeValue = "\u6536\u85cf\u6b64\u5546\u54c1";
		}
		if (!f) {
			return;
		}
		d.write($splat((d.read("S[GFAV]") || "").split(","))[b[h + "_"]](f).clean().join(","));
		new Request().post("index.php?member-" + f + "-ajax" + b[h] + "Fav.html", $H({t:$time()}));
	};
	var c = $splat((d.read("S[GFAV]") || "").split(","));
	$$("li[star]").each(function (f) {
		var e = f.get("star");
		if (c.contains(e)) {
			a(f, "on");
		}
		f.addEvent("click", function (g) {
			g.stop();
			a(f, b[f.className], e);
		});
	});
});
window.addEvent("domready", function () {
	var e = $("goods-compare") || new Element("div").set("html", ["<div class='FormWrap goods-compare' id='goods-compare' style='display:none'>", "<div class='title'><h3>\u5546\u54c1\u5bf9\u6bd4<span class='close-gc' onclick='gcompare.hide()'>[\u5173\u95ed]</span></h3></div>", "<form action='" + Shop.url.diff + "' method='post' target='_compare_goods'>", "<input type='hidden' name='t' value=" + $time() + ">", "<ul class='compare-box'>", "<li class='division clearfix tpl'>", "<div class='span-3'>", "<a href='#' gid='{gid}' title='{gname}'>{gname}</a>", "</div>", "<span class='floatRight lnk' onclick='gcompare.erase(\"{gid}\",this);'>\u5220\u9664</span>", "</li>", "</ul>", "<div class='compare-bar'>", "<input type='button' name='comareing' onclick='gcompare.submit()' class='btn-compare' value='\u5bf9\u6bd4'>", "<input type='button' class='btn-compare' onclick='gcompare.empty()' value='\u6e05\u7a7a'>", "</div>", "</form>", "</div>"].join("\n")).getFirst().inject(document.body);
	var d = e.getElement(".compare-box");
	var b = e.getElement(".compare-box .tpl").get("html");
	var f = "division clearfix";
	var c = function () {
		if (e.style.display == "none") {
			return;
		}
		e.setStyle("top", window.getScrollTop());
	};
	window.addEvents({resize:c, scroll:c});
	var a = new Cookie("S[GCOMPARE]");
	gcompare = {init:function () {
		var g = $splat((a.read("S[GCOMPARE]") || "").split("|")).erase("").clean();
		if (g.length) {
			g.each(function (h) {
				this.add(JSON.decode(h), true);
			}.bind(this));
		}
	}, hide:function () {
		e.hide();
	}, show:function () {
		e.show();
		c();
	}, add:function (g, k) {
		this.show();
		if (!k) {
			var j = $splat((a.read("S[GCOMPARE]") || "").split("|")).erase("").clean();
			if (j.length && j.some(function (l) {
				return (JSON.decode(l)["gtype"] + "_") != (g.gtype + "_");
			})) {
				return MessageBox.error("\u53ea\u80fd\u5bf9\u6bd4\u540c\u7c7b\u7684\u5546\u54c1.");
			}
			if (j.length > 4) {
				return MessageBox.error("\u6700\u591a\u53ea\u80fd\u5bf9\u6bd45\u4e2a\u5546\u54c1.");
			}
			a.write(j.include(JSON.encode(g)).join("|"));
		}
		if (d.getElement("a[gid=\"" + g.gid + "\"]")) {
			return;
		}
		var h = new Element("li", {"class":f}).set("html", b.substitute(g));
		var i = h.getElement("a");
		i.set("href", "?product-" + g.gid + ".html");
		d.adopt(h);
	}, erase:function (h, g) {
		var j = $splat((a.read("S[GCOMPARE]") || "").split("|")).erase("").clean();
		var i;
		j.each(function (m, k) {
			if (h == JSON.decode(m)["gid"]) {
				i = k;
			}
		});
		j.splice(i, 1);
		a.write(j.join("|"));
		$(g).getParent("li").remove();
	}, empty:function () {
		a.dispose();
		d.getElements("li").each(function (g) {
			if (!g.hasClass("tpl")) {
				return g.remove();
			}
		});
	}, submit:function () {
		if (Browser.Engine.webkit) {
			d.getParent("form").action = Shop.url.diff;
		}
		d.getParent("form").submit();
	}};
	gcompare.init();
});

